#pragma once
#include "DPiston.h"
#include "../DWorld.h"
#include "../DVector3.h"
#include "DJointGroup.h"

namespace Skill
{
	namespace Ode
	{
		namespace Joints
		{		
			void DPiston::CollectManagedMemory()
			{
				_Anchor1 = nullptr;
				_Anchor2 = nullptr;
				_Axis = nullptr;
				DJoint::CollectManagedMemory();
			}
			DPiston::DPiston(DWorld^ world , DJointGroup^ group)
				:DJoint(world,group)
			{
				dWorldID w = world? world->_This : NULL;
				dJointGroupID g = group? group->_This : NULL;
				_SetPointer(dJointCreatePiston(w,g),true);
			}
			DVector3^ DPiston::Anchor1::get()
			{
				if(!_Anchor1)
					_Anchor1 = gcnew DVector3();
				dJointGetPistonAnchor(_This,_Anchor1->_This);
				return _Anchor1;
			}
			void DPiston::Anchor1::set(DVector3^ value)
			{
				dJointSetPistonAnchor(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			void DPiston::SetAnchorOffset(dReal x, dReal y, dReal z, dReal dx, dReal dy, dReal dz)
			{
				dJointSetPistonAnchorOffset(_This,x,y,z,dx,dy,dz);
			}
			void DPiston::SetAnchorOffset(DVector3^ p, DVector3^ d)
			{
				dJointSetPistonAnchorOffset(_This,p->_This[0],p->_This[1],p->_This[2],d->_This[0],d->_This[1],d->_This[2]);
			}

			DVector3^ DPiston::Axis::get()
			{
				if(!_Axis)
					_Axis = gcnew DVector3();
				dJointGetPistonAxis(_This,_Axis->_This);
				return _Axis;
			}
			void DPiston::Axis::set(DVector3^ value)
			{
				dJointSetPistonAxis(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			void DPiston::SetParam(DJointParameters parameter, dReal value)
			{
				dJointSetPistonParam(_This,(int)parameter, value);
			}
			dReal DPiston::GetParam(DJointParameters parameter)
			{
				return dJointGetPistonParam(_This,(int)parameter);
			}

			void DPiston::AddForce(dReal force)
			{
				dJointAddPistonForce(_This,force);
			}

			dReal DPiston::Position::get()
			{
				return dJointGetPistonPosition(_This);
			}			
			dReal DPiston::PositionRate::get()
			{
				return dJointGetPistonPositionRate(_This);
			}			
			dReal DPiston::Angle::get()
			{
				return dJointGetPistonAngle(_This);
			}
			dReal DPiston::AngleRate::get()
			{
				return dJointGetPistonAngleRate(_This);
			}

			DVector3^ DPiston::Anchor2::get()
			{
				if(!_Anchor2)
					_Anchor2 = gcnew DVector3();
				dJointGetPistonAnchor2(_This,_Anchor2->_This);
				return _Anchor2;
			}
		}
	}
}